-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Make ops::DerefMut
a diagnostic item
#147643
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@relaxcn Why would it be a good idea to allow such calls in Deref(Mut) impls? |
Reference to rust-lang/rust-clippy#15392, I think it is make sense to me. |
/// *x = 'b'; | ||
/// assert_eq!('b', x.value); | ||
/// ``` | ||
#[lang = "deref_mut"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DerefMut
already has a lang item, can you use LangItem::DeferMut
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course. I can use it to archive the same goal.
But strangely enough, Deref
is both a language item and a diagnostic item:
rust/library/core/src/ops/deref.rs
Lines 133 to 139 in 4b94758
#[lang = "deref"] | |
#[doc(alias = "*")] | |
#[doc(alias = "&*")] | |
#[stable(feature = "rust1", since = "1.0.0")] | |
#[rustc_diagnostic_item = "Deref"] | |
#[rustc_const_unstable(feature = "const_convert", issue = "143773")] | |
pub const trait Deref: PointeeSized { |
Why not the DerefMut
to be a diagnostic item? Then we can use them uniformly like:
[sym::Deref, sym::DerefMut]
.iter()
.any(|&sym| cx.tcx.is_diagnostic_item(sym, trait_id))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this feels like a reason to remove the Deref
diagnostics item as well 😆
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😂 I'm just confused about it.
Is it bad to use diagnostics item?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no worries
I am actually not quite sure. Our general approach is to use lang_items instead of diagnostics items if they already exist.
I don't think there's a large reason for that and we may even want is_diagnostics_item
to also just lookup lang items 😁 actually, I think that would be a good improvement
The main reason seems to be "there should only be one consistent way to do things"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your explanation.
So I will close this PR.
BTW it will have a big influence if we remove Deref
diagnostics item because rust-clippy
use it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we have clippy
as a subtree, so we can update it in the same PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All right. Thank you.
I'm working on an enhancement to clippy::explicit_deref_methods, which would allow explicit
deref
orderef_mut
method calls in implementation of the theDeref
orDerefMut
trait, so I need aDerefMut
diagnostic item to check if we are already in the impl ofDerefMut
trait.